package com.luoxiang.socialandroid.activity;

import static com.luoxiang.lib_common.common.Constants.MmkvConst.ACCID;
import static com.luoxiang.lib_common.common.Constants.MmkvConst.DOMAIN;
import static com.luoxiang.lib_common.common.Constants.MmkvConst.EXTRA;
import static com.luoxiang.lib_common.common.Constants.MmkvConst.HOSTAUDIT;
import static com.luoxiang.lib_common.common.Constants.MmkvConst.IMTOKEN;
import static com.luoxiang.lib_common.common.Constants.MmkvConst.KEY;
import static com.luoxiang.lib_common.common.Constants.MmkvConst.TOKEN;
import static com.luoxiang.lib_common.common.Constants.MmkvConst.USERID;
import static com.luoxiang.lib_common.common.Constants.MmkvConst.USER_NAME;

import android.Manifest;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.allenliu.versionchecklib.v2.AllenVersionChecker;
import com.allenliu.versionchecklib.v2.builder.UIData;
import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.google.gson.Gson;
import com.luoxiang.socialandroid.BuildConfig;
import com.luoxiang.socialandroid.R;
import com.luoxiang.socialandroid.base.BaseActivity;
import com.luoxiang.socialandroid.bean.Charge;
import com.luoxiang.socialandroid.bean.ChargeBaen;
import com.luoxiang.socialandroid.bean.GetUserData;
import com.luoxiang.socialandroid.bean.LocalBean;
import com.luoxiang.socialandroid.bean.MineInfoBean;
import com.luoxiang.socialandroid.bean.NewVersionBean;
import com.luoxiang.socialandroid.bean.NumberBean;
import com.luoxiang.socialandroid.bean.VersionBean;
import com.luoxiang.socialandroid.dialog.NewVersionDialog;
import com.luoxiang.socialandroid.dialog.TipDialog;
import com.luoxiang.socialandroid.face.view.FaceBeautyActivity;
import com.luoxiang.socialandroid.utils.AESUtil;
import com.luoxiang.socialandroid.utils.CustomClickListener;
import com.luoxiang.socialandroid.utils.LoginUtil;
import com.luoxiang.socialandroid.utils.MmkvUtil;
import com.luoxiang.socialandroid.utils.NetUtils;
import com.luoxiang.socialandroid.utils.NetUtils2;
import com.lxj.xpopup.XPopup;
import com.netease.nis.quicklogin.QuickLogin;
import com.netease.yunxin.kit.corekit.im.IMKitClient;
import com.netease.yunxin.kit.corekit.im.login.LoginCallback;
import com.tbruyelle.rxpermissions2.RxPermissions;
import com.tcl.tclzjpro.common.manager.CacheDataManager;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;
import kotlin.Unit;
import kotlin.jvm.functions.Function0;

public class SetActivity extends BaseActivity {
    private String token;
    private TextView tx_charge, tx_version, num_huancun, bt_nologin, textWeChat;
    private RelativeLayout r_heimingdan, r_wuraomoshi, r_tonghuajiage, r_bangzhu, r_yinsixieyi, r_meiyancanshu, r_qinglihuancun, r_weChat;
    private ImageView icon_back, im_setlocal, im_setDND, imageWeChat;
    private Boolean isLocal = false, isDND = false;
    private int local, DND;
    private VersionBean bean;
    private int host;
    private int flag, flag1, flag2, wxShow;
    private RelativeLayout r_zhuxiao, r_jianchagengxin;
    private int identity;
    private TextView guanbitongcheng;
    private ImageView r_kaiqiyinsi;
    private RelativeLayout r_kaiqiyinsiewl;
    private RelativeLayout r_guanbitongcheng;
    private String nowVersion;

    @Override
    protected void initListener() {
        icon_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        im_setDND.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (flag == 0) {
                    flag = 1;
                    setDND(1);
                    iswurao();
                } else {
                    flag = 0;
                    setDND(0);
                    iswurao();
                }
            }
        });
        nologin();
        initOptionPicker();
        toblack();
        tohelp();
        toprivacy();
        tomeiyan();
        toqinglihuancun();
        r_zhuxiao.setOnClickListener(v -> {
            Intent intent = new Intent(SetActivity.this, IdSetActivity.class);
            startActivity(intent);
        });
    }

    private void toqinglihuancun() {
        r_qinglihuancun.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String totalCacheSize = CacheDataManager.INSTANCE.getTotalCacheSize(SetActivity.this);

                TipDialog tipDialog = new TipDialog(SetActivity.this);
                tipDialog.setTitle(getString(R.string.mi_caozuotishi));
                tipDialog.setCancel(getString(R.string.mi_quxiao));
                tipDialog.setContent(getString(R.string.mi_huancunshuliangwei) + totalCacheSize + getString(R.string.mi_ninquedingyaoqinglima));
                tipDialog.setConfirm(getString(R.string.mi_queding));
                tipDialog.setOnCancelClickListener(new Function0<Unit>() {
                    @Override
                    public Unit invoke() {
                        tipDialog.dismiss();
                        return null;
                    }
                });
                tipDialog.setOnConfirmClickListener(new Function0<Unit>() {
                    @Override
                    public Unit invoke() {
                        CacheDataManager.INSTANCE.clearAllCache(SetActivity.this);
                        if (CacheDataManager.INSTANCE.getTotalCacheSize(SetActivity.this).startsWith("0")) {
                            ToastUtils.showShort(R.string.mi_qingliwancheng);
                        }
                        tipDialog.dismiss();
                        return null;
                    }
                });
                new XPopup.Builder(SetActivity.this)
                        .asCustom(tipDialog)
                        .show();
            }
        });
    }

    private void tomeiyan() {
        r_meiyancanshu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                initScreenRecorderBuild();
                Intent intent = new Intent(SetActivity.this, FaceBeautyActivity.class);
                startActivity(intent);
            }
        });
    }

    private void initScreenRecorderBuild() {
        RxPermissions rxPermissions = new RxPermissions(this);
        rxPermissions.request(
                Manifest.permission.CAMERA


        ).subscribe(new Consumer<Boolean>() {
            @Override
            public void accept(Boolean aBoolean) throws Exception {
                if (aBoolean) {

                } else {
                    ToastUtils.showShort(R.string.mi_budakaiquanxianhuiyingxiangshiyong);
                }
            }
        });
    }

    private void toprivacy() {
        r_yinsixieyi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(SetActivity.this, PrivacyActivity.class);
                startActivity(intent);
            }
        });
    }

    private void tohelp() {
        r_bangzhu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(SetActivity.this, HelpActivity.class);
                startActivity(intent);
            }
        });
        r_jianchagengxin.setOnClickListener(new CustomClickListener() {
            @Override
            protected void onSingleClick() {
                getNewversion(MmkvUtil.INSTANCE.decodeString(TOKEN), EXTRA, "0");
            }

            @Override
            protected void onFastClick() {

            }
        });
    }

    private void getNewversion(String token, String extra, String type) {
        getRequest();
        com.luoxiang.lib_common.utils.NetUtils.getInstance().getApiService().getNewestVersion(token, extra, type)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new io.reactivex.Observer<com.luoxiang.lib_common.bean.NumberBean>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(com.luoxiang.lib_common.bean.NumberBean numberBean) {
                        String data = numberBean.getData();
                        String decryptStr = null;
                        try {
                            decryptStr = AESUtil.aesDecryptString(data, KEY);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        LogUtils.i("decryptStr800", decryptStr);
                        Gson gson = new Gson();
                        NewVersionBean newVersionBean = gson.fromJson(decryptStr, NewVersionBean.class);
                        if (newVersionBean.getData() != null) {
                            NewVersionDialog dialog = new NewVersionDialog(SetActivity.this);
                            String version = newVersionBean.getData().getVersion().getVersion();

                            if (!nowVersion.equals("V" + BuildConfig.VERSION_NAME) && newVersionBean.getData().getVersion().getStatus() == 0) {
                                dialog.setOnConfirmClickListener(new Function0<Unit>() {
                                    @Override
                                    public Unit invoke() {
                                        //点击确定
                                        AllenVersionChecker
                                                .getInstance()
                                                .downloadOnly(
                                                        UIData.create().setDownloadUrl(DOMAIN + newVersionBean.getData().getVersion().getUrl())
                                                                .setTitle("当前有新版本" + version)
                                                                .setContent(newVersionBean.getData().getVersion().getContent())
                                                )
                                                .executeMission(SetActivity.this);
                                        return null;
                                    }
                                });
                                dialog.setOnCancleClickListener(new Function0<Unit>() {
                                    @Override
                                    public Unit invoke() {
                                        finishAll();
                                        dialog.dismiss();
                                        return null;
                                    }
                                });
                                dialog.setTitle(newVersionBean.getData().getVersion().getVersion() + getString(R.string.mi_banbengengxintongzhi));//设置title
                                dialog.setContent(newVersionBean.getData().getVersion().getContent());//设置文本
                                new XPopup.Builder(SetActivity.this)
                                        .asCustom(dialog)
                                        .show();
                            } else {
                                ToastUtils.showShort(R.string.mi_yijingshizuixinbanben);
                                return;
                            }

                        }


                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    @Override
    protected void initView() {
        token = MmkvUtil.INSTANCE.decodeString(TOKEN);
        getRequest();
        r_heimingdan = findViewById(R.id.r_heimingdan);
        im_setlocal = findViewById(R.id.im_setlocal);
        im_setDND = findViewById(R.id.im_setDND);
        icon_back = findViewById(R.id.icon_back);
        bt_nologin = findViewById(R.id.bt_nologin);
        r_wuraomoshi = findViewById(R.id.r_wuraomoshi);
        r_tonghuajiage = findViewById(R.id.r_tonghuajiage);
        r_yinsixieyi = findViewById(R.id.r_yinsixieyi);
        r_bangzhu = findViewById(R.id.r_bangzhu);
        r_meiyancanshu = findViewById(R.id.r_meiyancanshu);
        r_qinglihuancun = findViewById(R.id.r_qinglihuancun);
        tx_charge = findViewById(R.id.tx_charge);
        tx_version = findViewById(R.id.tx_version);
        num_huancun = findViewById(R.id.num_huancun);
        r_zhuxiao = findViewById(R.id.r_zhuxiao);
        r_jianchagengxin = findViewById(R.id.r_jianchagengxin);
        guanbitongcheng = findViewById(R.id.guanbitongcheng);
        r_kaiqiyinsi = findViewById(R.id.im_setyinsi);
        r_kaiqiyinsiewl = findViewById(R.id.r_kaiqiyinsi);
        r_guanbitongcheng = findViewById(R.id.r_guanbitongcheng);
        imageWeChat = findViewById(R.id.imageWeChat);
        textWeChat = findViewById(R.id.textWeChat);
        r_weChat = findViewById(R.id.r_weChat);
        getUserInfo(token, EXTRA);
        setversion();

        NetUtils2.getInstance().getApiService().getHomeUserInfo(token, EXTRA)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<NumberBean>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(NumberBean numberBean) {
                        String data = numberBean.getData();
                        String decryptStr = null;
                        try {
                            decryptStr = AESUtil.aesDecryptString(data, KEY);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        try {
                            LogUtils.i("decryptStr0", decryptStr);
                            Gson gson = new Gson();

                            MineInfoBean bean = gson.fromJson(decryptStr, MineInfoBean.class);
                            host = bean.getData().getUser().getHost();
                            if (host == 0) {
                                r_tonghuajiage.setVisibility(View.GONE);
                            }
                        } catch (Exception e) {
                            LogUtils.i("decryptStr0", e.getMessage());
                        }
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });

    }


    private void setversion() {
        NetUtils2.getInstance().getApiService().getNewestVersion(token, EXTRA, "0")
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<NumberBean>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(NumberBean numberBean) {
                        String data = numberBean.getData();
                        String decryptStr = null;
                        try {
                            decryptStr = AESUtil.aesDecryptString(data, KEY);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        LogUtils.i("decryptStr41", decryptStr);
                        Gson gson = new Gson();
                        bean = gson.fromJson(decryptStr, VersionBean.class);
                        tx_version.setText("V" + BuildConfig.VERSION_NAME);
                        nowVersion = bean.getData().getVersion().getVersion();
                    }

                    @Override
                    public void onError(Throwable e) {
                        log(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    private void initOptionPicker() {
        r_tonghuajiage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                NetUtils2.getInstance().getApiService().getCharge(token, EXTRA)
                        .subscribeOn(Schedulers.io())
                        .observeOn(AndroidSchedulers.mainThread())
                        .subscribe(new Observer<NumberBean>() {
                            @Override
                            public void onSubscribe(Disposable d) {

                            }

                            @Override
                            public void onNext(NumberBean numberBean) {
                                String data = numberBean.getData();
                                String decryptStr = null;
                                try {
                                    decryptStr = AESUtil.aesDecryptString(data, KEY);
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                                LogUtils.i("decryptStr44", decryptStr);
                                Gson gson = new Gson();
                                ChargeBaen bean = gson.fromJson(decryptStr, ChargeBaen.class);

                                ArrayList<String> strings = new ArrayList<>();
                                ArrayList<String> ids = new ArrayList<>();
                                if (bean != null) {
                                    if (bean.getData() != null && bean.getData().getCharges().size() != 0) {
                                        List<Charge> charges = bean.getData().getCharges();
                                        for (int i = 0; i < charges.size(); i++) {
                                            strings.add(charges.get(i).getCharge() + getString(R.string.mi_mifenzhong));
                                            ids.add(charges.get(i).getId() + "");
                                        }
                                        OptionsPickerView pvOptions = new OptionsPickerBuilder(SetActivity.this, new OnOptionsSelectListener() {
                                            @Override
                                            public void onOptionsSelect(int options1, int option2, int options3, View v) {
                                                //返回的分别是三个级别的选中位置
                                                String tx = strings.get(options1);
                                                tx_charge.setText(tx);
                                                int channelIndex = options1;
                                                String channelNoName = strings.get(options1);
                                                tx_charge.setText(channelNoName + "");

                                                NetUtils2.getInstance().getApiService().setCharge(token, EXTRA, ids.get(options1))
                                                        .subscribeOn(Schedulers.io())
                                                        .observeOn(AndroidSchedulers.mainThread())
                                                        .subscribe(new Observer<NumberBean>() {
                                                            @Override
                                                            public void onSubscribe(Disposable d) {
                                                            }

                                                            @Override
                                                            public void onNext(NumberBean numberBean) {
                                                                String data = numberBean.getData();
                                                                String decryptStr = null;
                                                                try {
                                                                    decryptStr = AESUtil.aesDecryptString(data, KEY);
                                                                } catch (Exception e) {
                                                                    e.printStackTrace();
                                                                }
                                                                LogUtils.i("decryptStrprice", decryptStr);
                                                            }

                                                            @Override
                                                            public void onError(Throwable e) {
                                                            }

                                                            @Override
                                                            public void onComplete() {
                                                            }
                                                        });
                                            }
                                        }).build();

                                        pvOptions.setPicker(strings);
                                        pvOptions.show();

                                    }
                                }
                            }

                            @Override
                            public void onError(Throwable e) {

                            }

                            @Override
                            public void onComplete() {

                            }
                        });

            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        getUserInfo(token, EXTRA);
    }

    /**
     * 勿扰模式设置
     */
    private void setDND(int DND) {
        getRequest();
        NetUtils2.getInstance().getApiService().setDND(DND, token, EXTRA)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<NumberBean>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(NumberBean numberBean) {
                        String data = numberBean.getData();
                        String decryptStr = null;
                        try {
                            decryptStr = AESUtil.aesDecryptString(data, KEY);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        LogUtils.i("decryptStr4", decryptStr);
                        Gson gson = new Gson();
                        LocalBean bean = gson.fromJson(decryptStr, LocalBean.class);
                        if (bean.getCode() == 0) {
                            ToastUtils.showShort(R.string.mi_shezhichenggong);
                        } else {
                            ToastUtils.showShort(bean.getMsg());
                            getUserInfo(token, EXTRA);
                        }
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    private void setisDND() {

    }

    private void iswurao() {
        //是否关注
        if (flag == 0) {
            //未开启
            im_setDND.setImageResource(R.mipmap.icon_weixuanzhong);

        } else {
            //已开启
            im_setDND.setImageResource(R.mipmap.icon_xuanzhong);

        }
    }

    private void istongcheng() {
        //是否关注
        if (flag1 == 0) {
            //开启
            im_setlocal.setImageResource(R.mipmap.icon_xuanzhong);
            guanbitongcheng.setText("关闭同城");

        } else {
            //已开启
            im_setlocal.setImageResource(R.mipmap.icon_weixuanzhong);
            guanbitongcheng.setText("开启同城");

        }
    }

    private void isShowWeChat() {
        //是否关注
        if (wxShow == 1) {
            //开启
            imageWeChat.setImageResource(R.mipmap.icon_xuanzhong);
            textWeChat.setText("显示微信");

        } else {
            //已开启
            imageWeChat.setImageResource(R.mipmap.icon_weixuanzhong);
            textWeChat.setText("隐藏微信");

        }
    }


    private void isyinsi() {
        if (flag2 == 0) {
            //未开启
            r_kaiqiyinsi.setImageResource(R.mipmap.icon_weixuanzhong);

        } else {
            //已开启
            r_kaiqiyinsi.setImageResource(R.mipmap.icon_xuanzhong);

        }
    }

    private void getUserInfo(String token, String extra) {
        getRequest();
        NetUtils.getInstance().getApiService().getMineUserInfo(token, extra)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<NumberBean>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(NumberBean numberBean) {
                        String data = numberBean.getData();
                        String decryptStr = null;
                        try {
                            decryptStr = AESUtil.aesDecryptString(data, KEY);
                            LogUtils.i("decryptStrpq", decryptStr);
                            Gson gson = new Gson();
                            GetUserData bean = gson.fromJson(decryptStr, GetUserData.class);
                            flag = bean.getData().getUser().getDnd();
                            flag1 = bean.getData().getUser().getLocal();
                            flag2 = bean.getData().getUser().getPrivacy();
                            wxShow = bean.getData().getUser().getWxShow();
                            if (bean.getData().getUser() != null) {
                                int charge = bean.getData().getUser().getCharge();
                                tx_charge.setText(charge + getString(R.string.mi_mifenzhong));
                            }
                            if (bean.getData().getUser().getHost() == 1) {
                                //表示是主播
                                r_weChat.setVisibility(View.VISIBLE);
                                r_kaiqiyinsiewl.setVisibility(View.GONE);
                                r_guanbitongcheng.setVisibility(View.VISIBLE);
                                imageWeChat.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View view) {
                                        if (wxShow == 0) {
                                            //如果开启
                                            wxShow = 1;
                                        } else {
                                            wxShow = 0;
                                        }
                                        setShowWeChat(wxShow);
                                        isShowWeChat();
                                    }
                                });
                                im_setlocal.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View view) {
                                        if (flag1 == 0) {
                                            //如果开启
                                            flag1 = 1;
                                            setlocal(flag1);
                                            istongcheng();
                                        } else {
                                            flag1 = 0;
                                            setlocal(flag1);
                                            istongcheng();
                                        }
                                    }
                                });

                            } else {
                                //在这里显示
                                r_kaiqiyinsiewl.setVisibility(View.GONE);
                                r_guanbitongcheng.setVisibility(View.GONE);
                                r_kaiqiyinsi.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View view) {
                                        if (identity == 0) {
                                            TipDialog tipDialog = new TipDialog(SetActivity.this);
                                            tipDialog.setTitle(getString(R.string.mi_xml_caozuotishi));
                                            tipDialog.setCancel(getString(R.string.mi_zaidengdeng));
                                            tipDialog.setContent(getString(R.string.mi_dialog_vip_content));
                                            tipDialog.setConfirm(getString(R.string.mi_kaitonghuiyuan));
                                            tipDialog.setOnCancelClickListener(new Function0<Unit>() {
                                                @Override
                                                public Unit invoke() {
                                                    tipDialog.dismiss();
                                                    return null;
                                                }
                                            });
                                            tipDialog.setOnConfirmClickListener(new Function0<Unit>() {
                                                @Override
                                                public Unit invoke() {
                                                    Intent intent = new Intent(SetActivity.this, VipActivity.class);
                                                    startActivity(intent);
                                                    tipDialog.dismiss();
                                                    return null;
                                                }
                                            });
                                            new XPopup.Builder(SetActivity.this)
                                                    .asCustom(tipDialog)
                                                    .show();
                                        } else {
                                            if (flag2 == 0) {
                                                flag2 = 1;
                                                setPrivacy(1);
                                                isyinsi();
                                            } else {
                                                flag2 = 0;
                                                setPrivacy(0);
                                                isyinsi();
                                            }
                                        }

                                    }
                                });
                            }
                            identity = bean.getData().getUser().getIdentity();
                            LogUtils.i("falggggggg", bean.getData().getUser().getDnd());
                            iswurao();
                            istongcheng();
                            isShowWeChat();
                            isyinsi();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });

    }


    private void toblack() {
        r_heimingdan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(SetActivity.this, BlackActivity.class);
                startActivity(intent);
            }
        });
    }


    private void nologin() {
        bt_nologin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                TipDialog tipDialog = new TipDialog(SetActivity.this);
                tipDialog.setTitle(getString(R.string.mi_xml_caozuotishi));
                tipDialog.setCancel(getString(R.string.mi_quxiao));
                tipDialog.setContent(getString(R.string.mi_exit_app));
                tipDialog.setConfirm(getString(R.string.mi_queding));
                tipDialog.setOnCancelClickListener(new Function0<Unit>() {
                    @Override
                    public Unit invoke() {
                        tipDialog.dismiss();
                        return null;
                    }
                });
                tipDialog.setOnConfirmClickListener(new Function0<Unit>() {
                    @Override
                    public Unit invoke() {
                        getlogout(EXTRA, MmkvUtil.INSTANCE.decodeString(TOKEN));
                        MmkvUtil.INSTANCE.encode(TOKEN, "");
                        MmkvUtil.INSTANCE.encode(ACCID, "");
                        MmkvUtil.INSTANCE.encode(IMTOKEN, "");
                        MmkvUtil.INSTANCE.encode(HOSTAUDIT, "");
                        MmkvUtil.INSTANCE.encode(USER_NAME, "");
                        MmkvUtil.INSTANCE.encode("phone", "");
                        MmkvUtil.INSTANCE.encode(USERID, "");
                        MmkvUtil.INSTANCE.encode("datingModeId", "");
                        MmkvUtil.INSTANCE.encode("emotioRelationId", "");
                        MmkvUtil.INSTANCE.encode("targetAgeId", "");
                        MmkvUtil.INSTANCE.encode("sexpait", "");
                        MmkvUtil.INSTANCE.encode("ed_rename", "");
                        MmkvUtil.INSTANCE.encode("isshowdialogbatch", "");
                        MmkvUtil.INSTANCE.encode("usericon", "");
                        IMKitClient.logoutIM(new LoginCallback<Void>() {
                            @Override
                            public void onError(int i, @NonNull String s) {
                                ToastUtils.showShort(s);
                            }

                            @Override
                            public void onSuccess(@Nullable Void unused) {

                            }
                        });
                        try {
                            HomeActivity.instance.finish();

                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        LoginUtil.Companion.initLogin(
                                SetActivity.this,
                                result -> {
                                    LoginUtil.Companion.startLogin(SetActivity.this, result);
                                    finish();
                                    return null;
                                },
                                () -> {
                                    showLoading();
                                    return null;
                                },
                                () -> {
                                    clearLoading();
                                    return null;
                                });
                        return null;
                    }
                });
                new XPopup.Builder(SetActivity.this)
                        .asCustom(tipDialog)
                        .show();

            }
        });
    }

    private void getlogout(String extra, String token) {
        NetUtils.getInstance().getApiService().getlogout(extra, token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<NumberBean>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(NumberBean numberBean) {
                        String data = numberBean.getData();
                        String decryptStr = null;
                        try {
                            decryptStr = AESUtil.aesDecryptString(data, KEY);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        LogUtils.i("decryptStr22", decryptStr);
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    @Override
    protected void initLayout(Bundle savedInstanceState) {
        setContentView(R.layout.activity_set);
        setStatusBarTranslucent();
    }

    private void setShowWeChat(int wxShow){
        int s;
        if (wxShow == 0){
            s = 1;
        }else{
            s = 0;
        }
        NetUtils2.getInstance().getApiService().setShowWeChat(token, EXTRA,s)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<NumberBean>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(NumberBean value) {
                        String data = value.getData();
                        String decryptStr = null;
                        try {
                            decryptStr = AESUtil.aesDecryptString(data, KEY);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        Gson gson = new Gson();
                        LocalBean bean = gson.fromJson(decryptStr, LocalBean.class);
                        if (bean.getCode() == 0) {
                            ToastUtils.showShort(R.string.mi_shezhichenggong);
                        } else {
                            ToastUtils.showShort(bean.getMsg());
                        }
                        getUserInfo(token, EXTRA);
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    private void setlocal(int local) {
        NetUtils2.getInstance().getApiService().setLocal(local, token, EXTRA)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<NumberBean>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(NumberBean numberBean) {
                        String data = numberBean.getData();
                        String decryptStr = null;
                        try {
                            decryptStr = AESUtil.aesDecryptString(data, KEY);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        LogUtils.i("decryptStr2", decryptStr);
                        Gson gson = new Gson();
                        LocalBean bean = gson.fromJson(decryptStr, LocalBean.class);
                        if (bean.getCode() == 0) {
                            ToastUtils.showShort(R.string.mi_shezhichenggong);
                        } else {
                            ToastUtils.showShort(bean.getMsg());
                            getUserInfo(token, EXTRA);
                        }
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });

    }

    /**
     * 隐私模式状态设置
     */
    private void setPrivacy(int privacy) {
        NetUtils.getInstance().getApiService().setPrivacy(EXTRA, token, privacy)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<NumberBean>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(NumberBean numberBean) {
                        String data = numberBean.getData();
                        String decryptStr = null;
                        try {
                            decryptStr = AESUtil.aesDecryptString(data, KEY);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        LogUtils.i("decryptStr2", decryptStr);
                        Gson gson = new Gson();
                        LocalBean bean = gson.fromJson(decryptStr, LocalBean.class);
                        if (bean.getCode() == 0) {
                            ToastUtils.showShort(R.string.mi_shezhichenggong);
                        } else {
                            ToastUtils.showShort(bean.getMsg());
                            getUserInfo(token, EXTRA);
                        }
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

}
